package ServerData;

import Server.Domain.User;
import Server.Task;

import java.util.concurrent.ConcurrentHashMap;

public class ServerTaskData {
    ConcurrentHashMap<String, Task> map = new ConcurrentHashMap<>();

    public void setTaskData(User user, Task task){
        map.put(user.getName(),task);
    }

    public Task getTask(String name){
        return map.getOrDefault(name, null);
    }
    public Task[] getTasks(String name){
        Task[] tasks = new Task[map.size() - 1];
        int i = 0;
        for(String name0 : map.keySet()){
            if(!name0.equals(name)){
                tasks[i] = map.get(name0);
                i++;
            }
        }
        return tasks;
    }
    public Task[] getAllTasks(){
        Task[] tasks = new Task[map.size()];
        int i = 0;
        for(String name : map.keySet()){
                tasks[i] = map.get(name);
                i++;
            }
        return tasks;
    }
}

